#include "Graphics/IViewport.h"

namespace tyro
{
	namespace Graphics
	{


		IViewport::IViewport( Camera::Camera* camera, Graphics::IRenderTarget* target, FLOAT_32 left, FLOAT_32 top, FLOAT_32 width, FLOAT_32 height )
			: activeCamera(camera)
			, target(target)
			, relLeft(left)
			, relTop(top)
			, relWidth(width)
			, relHeight(height)
			, clearBuffers( FBT_COLOUR | FBT_DEPTH)
			, depthClear(1)
			, backColour(Graphics::Colour::White)
			, clearEachFrame(true)
		{
			//UpdateDimensions();
		}

		Camera::Camera* IViewport::GetCamera() const
		{
			return activeCamera;
		}

		void IViewport::SetCamera( Camera::Camera* camera )
		{
			this->activeCamera = camera; 
		}

		Graphics::IRenderTarget* IViewport::GetRenderTarget() const
		{
			return target;
		}

		void IViewport::SetRenderTarget( Graphics::IRenderTarget* target )
		{
			this->target = target;
		}

		tyro::FLOAT_32 IViewport::GetRelLeft() const
		{
			return relLeft;
		}

		void IViewport::SetRelLeft( tyro::FLOAT_32 val )
		{
			relLeft = val;
		}

		tyro::FLOAT_32 IViewport::GetRelHeight() const
		{
			return relHeight;
		}

		void IViewport::SetRelHeight( tyro::FLOAT_32 val )
		{
			relHeight = val;
		}

		tyro::FLOAT_32 IViewport::GetRelWidth() const
		{
			return relWidth;
		}

		void IViewport::SetRelWidth( tyro::FLOAT_32 val )
		{
			relWidth = val;
		}

		tyro::FLOAT_32 IViewport::GetRelTop() const
		{
			return relTop;
		}

		void IViewport::SetRelTop( tyro::FLOAT_32 val )
		{
			relTop = val;
		}

		tyro::UINT_32 IViewport::GetActHeight() const
		{
			return actHeight;
		}

		void IViewport::SetActHeight( tyro::UINT_32 val )
		{
			actHeight = val;
		}

		tyro::UINT_32 IViewport::GetActWidth() const
		{
			return actWidth;
		}

		void IViewport::SetActWidth( tyro::UINT_32 val )
		{
			actWidth = val;
		}

		tyro::UINT_32 IViewport::GetActTop() const
		{
			return actTop;
		}

		void IViewport::SetActTop( tyro::UINT_32 val )
		{
			actTop = val;
		}

		tyro::UINT_32 IViewport::GetActLeft() const
		{
			return actLeft;
		}

		void IViewport::SetActLeft( tyro::UINT_32 val )
		{
			actLeft = val;
		}

		tyro::Graphics::Colour IViewport::GetBackColour() const
		{
			return backColour;
		}

		void IViewport::SetBackColour( tyro::Graphics::Colour val )
		{
			backColour = val;
		}

		tyro::FLOAT_32 IViewport::GetDepthClear() const
		{
			return depthClear;
		}

		void IViewport::SetDepthClear( tyro::FLOAT_32 val )
		{
			depthClear = val;
		}

		void IViewport::Update( void )
		{	
			if(activeCamera)
			{
				// Render camera to the current target
				activeCamera->RenderScene(this);
			}
		}

		void IViewport::UpdateDimensions( void )
		{
			FLOAT_32 height = (FLOAT_32) target->getHeight();
			FLOAT_32 width = (FLOAT_32) target->getWidth();

			actLeft = (INT) (relLeft * width);
			actTop = (INT) (relTop * height);
			actWidth = (INT) (relWidth * width);
			actHeight = (INT) (relHeight * height);
		}

		bool IViewport::GetClearEachFrame()
		{
			return clearEachFrame;
			

		}

		tyro::UINT_32 IViewport::GetClearBuffers( void ) const
		{
			return clearBuffers;
		}

	}
}